package com.weigee.ktv.m.observer;

import android.app.Activity;
import android.os.Handler;
import android.support.annotation.NonNull;

import com.l.d.app.library.app.FragActivity;
import com.weigee.ktv.v.activity.ActivityUtil;
import com.weigee.ktv.v.activity.SingleTaskActivity;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * Created by 林德 on 2017/4/4 15:57.
 * <p/>
 */
public final class StartMainActivityObserver implements Observer<Long>
{
    @NonNull
    private final Activity mContext;

    public StartMainActivityObserver(@NonNull Activity context) {this.mContext = context;}

    @Override
    public void onSubscribe(Disposable d)
    {
    }

    @Override
    public void onNext(Long delayMillis)
    {
        if (delayMillis < 0)
        {
            delayMillis = 1000L;
        }
        new Handler().postDelayed(new Runnable()
        {
            @Override
            public void run()
            {
//                Intent intent = new Intent(mContext, StandardActivity.class);
//                intent.putExtra(FragActivity.TAG_FRAGMENT, "Main");
//                mContext.startActivity(intent);
                FragActivity.start(SingleTaskActivity.class, mContext, ActivityUtil.MAIN);
                mContext.finish();
            }
        }, delayMillis);
    }

    @Override
    public void onError(Throwable e)
    {
        e.printStackTrace();
    }

    @Override
    public void onComplete()
    {
    }
}
